Option Explicit
Sub O_Sample004()
    O_Sample004_1 Application.VBE.ActiveVBProject.VBComponents("Sheet1")
End Sub

Sub O_Sample004_1(myVbc As VBIDE.VBComponent)
    Dim myName    As String
    Dim myTmpName As String
    Dim myCode    As String
    Dim myImpVbc  As VBIDE.VBComponent
    Dim myPath    As String                  'ץXƧ
    With myVbc
        myPath = ThisWorkbook.Path
        myName = .Name                                  'xsҲզW
        myTmpName = myName & "_ZZZ"
        On Error Resume Next
        Kill myPath & myName & ".bas"                   'ץX
        On Error GoTo 0
        .Export myPath & myName & ".bas"                'ץX
        Select Case .Type
            Case vbext_ct_Document                      'Ҳծ
                With .Collection
                     Set myImpVbc = .Import(myPath & myName & ".bas") 'פJ
                    'ѶפJҲըo{X
                    With myImpVbc.CodeModule
                        myCode = .Lines(1, .CountOfLines)
                    End With
                    With myVbc.CodeModule
                        .DeleteLines 1, .CountOfLines    'RҲյ{X
                        .InsertLines 1, myCode          'Jwo{X
                    End With
                    .Remove myImpVbc                    'RҶפJҲ
                    Set myImpVbc = Nothing      '
                End With
            Case Else                                           'ҲեH~
                .Name = myTmpName                       'ܧҲզWٍX
                With .Collection
                    .Import myPath & myName & ".bas"    'פJ
                    .Remove myVbc                       'RҲ
                End With
        End Select
    End With
End Sub
